<template>
  <div class="filter">
    <div class="filter_item">
      姓名：<Input
        v-model="data.userName"
        clearable
        placeholder="请填写姓名"
        style="width: 300px"
      />
    </div>
    <div class="filter_item">
      性别：<Select
        v-model="data.sex"
        clearable
        style="width: 200px"
        @on-change="sexChange"
      >
        <Option v-for="item in sexs" :value="item.key" :key="item.value">{{
          item.key
        }}</Option>
      </Select>
    </div>
    <div class="filter_item">
      电话：<Input
        v-model="data.phone"
        :maxlength="11"
        show-word-limit
        clearable
        placeholder="请填写电话"
        style="width: 300px"
      />
    </div>
    <div class="filter_item">
      身份证号码：<Input
        v-model="data.identy"
        :maxlength="18"
        show-word-limit
        clearable
        placeholder="请填写身份证号码"
        style="width: 300px"
      />
    </div>
    <div class="filter_item">
      <Button @click="deleteContainer" type="error">Delete</Button>
    </div>
    <Divider />
  </div>
</template>

<script>
export default {
  name: "AddContainer",
  props: {
    index: {
      type: Number,
      required: true,
    },
    items: {
      type: Array,
      default: Array,
    },
  },
  data() {
    return {
      sexs: [
        { key: "男", value: "男" },
        { key: "女", value: "女" },
      ],
      data: {
        userName: "",
        sex: "",
        phone: "",
        identy: "",
        roomNumber: 0,
      },
    };
  },
  watch: {
    data: {
      handler(newV, oldV) {
        if (newV.userName.length === 0) {
          return false;
        }
        if (newV.sex.length === 0) {
          return false;
        }
        if (newV.phone.length === 0) {
          return false;
        }
        if (newV.identy.length === 0) {
          return false;
        }
        if (newV.roomNumber.length === 0) {
          return false;
        }
        this.$emit("uploadData", { index: this.index, data: newV });
      },
      deep: true
    }
  },
  methods: {
    sexChange(e) {
      this.sex = e;
    },
    deleteContainer() {
        this.$emit('deleteIndex', this.index);
    }
  },
};
</script>
<style>
.filter {
  display: flex;
  flex-wrap: wrap;
  height: 700;
}
.filter_item {
  margin-left: 30px;
  margin-top: 30px;
  float: left;
}
</style>